home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS 1.31 / antlr / syn.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-10  |  9.9 KB  |  303 lines  |  [TEXT/MPS ]

  1. /*
  2.  * syn.h
  3.  *
  4.  * $Id: syn.h,v 1.13 1994/12/31 21:02:55 parrt Exp parrt $
  5.  * $Revision: 1.13 $
  6.  *
  7.  * This file includes definitions and macros associated with syntax diagrams
  8.  *
  9.  * SOFTWARE RIGHTS
  10.  *
  11.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  12.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  13.  * company may do whatever they wish with source code distributed with
  14.  * PCCTS or the code generated by PCCTS, including the incorporation of
  15.  * PCCTS, or its output, into commerical software.
  16.  * 
  17.  * We encourage users to develop software with PCCTS.  However, we do ask
  18.  * that credit is given to us for developing PCCTS.  By "credit",
  19.  * we mean that if you incorporate our source code into one of your
  20.  * programs (commercial product, research project, or otherwise) that you
  21.  * acknowledge this fact somewhere in the documentation, research report,
  22.  * etc...  If you like PCCTS and have developed a nice tool with the
  23.  * output, please mention that you developed it using PCCTS.  In
  24.  * addition, we ask that this header remain intact in our source code.
  25.  * As long as these guidelines are kept, we expect to continue enhancing
  26.  * this system and expect to make other tools available as they are
  27.  * completed.
  28.  *
  29.  * ANTLR 1.31
  30.  * Terence Parr
  31.  * Parr Research Corporation
  32.  * with Purdue University and AHPCRC, University of Minnesota
  33.  * 1989-1995
  34.  */
  35.  
  36. #define NumNodeTypes    4
  37. #define NumJuncTypes    9
  38.  
  39. /* List the different node types */
  40. #define nJunction        1
  41. #define nRuleRef        2
  42. #define nToken            3
  43. #define nAction            4
  44.  
  45. /* Different types of junctions */
  46. #define aSubBlk            1
  47. #define aOptBlk            2
  48. #define aLoopBlk        3
  49. #define EndBlk            4
  50. #define RuleBlk            5
  51. #define Generic            6    /* just a junction--no unusual characteristics */
  52. #define EndRule            7
  53. #define aPlusBlk        8
  54. #define aLoopBegin        9
  55.  
  56. typedef int NodeType;
  57.  
  58. #define TreeBlockAllocSize        500
  59. #define JunctionBlockAllocSize    200
  60. #define ActionBlockAllocSize    50
  61. #define RRefBlockAllocSize        100
  62. #define TokenBlockAllocSize        100
  63.  
  64. /* note that 'right' is used by the tree node allocator as a ptr for linked list */
  65. typedef struct _tree {
  66.             struct _tree *down, *right;
  67.             int token;
  68.             union {
  69.                 int rk;    /* if token==EpToken, => how many more tokens req'd */
  70.                 struct _tree *tref;    /* if token==TREE_REF */
  71.                 set sref;            /* if token==SET */
  72.             } v;
  73. #ifdef TREE_DEBUG
  74.             int in_use;
  75. #endif
  76.         } Tree;
  77.  
  78. /* a predicate is defined to be a predicate action and a token tree with
  79.  * context info (if used); later, this struct may include the
  80.  * "hoisting distance" when we hoist past tokens.
  81.  *
  82.  * A tree is used to indicate && vs ||
  83.  *
  84.  *    p
  85.  *    |
  86.  *    q--r
  87.  *
  88.  * indicates p && (q||r).
  89.  */
  90. typedef struct _Predicate {
  91.     struct _Predicate *down, *right;    /* these have to be first */
  92.     char *expr;
  93.     Tree *tcontext;    /* used if lookahead depth of > one is needed (tree) */
  94.     set scontext[2];/* used if lookahead depth of one is needed (set) */
  95.                     /* scontext[0] is not used; only needed so genExprSets()
  96.                        routine works (it expects an array)
  97.                      */
  98.     set completion;    /* which lookahead depths are required to complete tcontext? */
  99. } Predicate;
  100.  
  101. typedef struct _ExceptionHandler {
  102.             char *signalname;
  103.             char *action;
  104.         } ExceptionHandler;
  105.  
  106. typedef struct _ExceptionGroup {
  107.             struct _ListNode *handlers; /* list of ExceptionHandler's */
  108.             char *label;        /* label==""; implies not attached to any
  109.                                  * particular rule ref.
  110.                                  */
  111.             char *altID;        /* which alt did it come from (blk#:alt#) */
  112.         } ExceptionGroup ;
  113.  
  114.  
  115. #define TokenString(_i)            ((TokenInd!=NULL)?TokenStr[TokenInd[_i]]:TokenStr[_i])
  116. #define ExprString(_i)            ((TokenInd!=NULL)?ExprStr[TokenInd[_i]]:ExprStr[_i])
  117.  
  118.  
  119.                 /* M e s s a g e  P a s s i n g  T o  N o d e s */
  120.  
  121. /*
  122.  * assumes a 'Junction *r' exists.  This macro calls a function with
  123.  * the pointer to the node to operate on and a pointer to the rule
  124.  * in which it is enclosed.
  125.  */
  126. #define TRANS(p)    {if ( (p)==NULL ) fatal("TRANS: NULL object");        \
  127.                     if ( (p)->ntype == nJunction ) (*(fpJTrans[((Junction *)(p))->jtype]))( p );\
  128.                     else (*(fpTrans[(p)->ntype]))( p );}
  129.  
  130. #define PRINT(p)    {if ( (p)==NULL ) fatal("PRINT: NULL object");\
  131.                     (*(fpPrint[(p)->ntype]))( p );}
  132.  
  133. #define REACH(p,k,rk,a) {if ( (p)==NULL ) fatal("REACH: NULL object");\
  134.                     (a) = (*(fpReach[(p)->ntype]))( p, k, rk );}
  135.  
  136. #define TRAV(p,k,rk,a) {if ( (p)==NULL ) fatal("TRAV: NULL object");\
  137.                     (a) = (*(fpTraverse[(p)->ntype]))( p, k, rk );}
  138.  
  139. /* All syntax diagram nodes derive from Node -- superclass
  140.  */
  141. #ifdef __cplusplus
  142. class Node {
  143. public:
  144.             NodeType ntype;
  145.         };
  146. #else
  147. typedef struct _node {
  148.             NodeType ntype;
  149.         } Node;
  150. #endif
  151.  
  152. #ifdef __cplusplus
  153. class ActionNode : public Node {
  154. public:
  155. #else
  156. typedef struct _anode {
  157.             NodeType ntype;
  158. #endif
  159.             Node *next;
  160.             char *action;
  161.             int file;            /* index in FileStr (name of file with action) */
  162.             int line;            /* line number that action occurs on */
  163.             int is_predicate;    /* true if action is a <<...>>? predicate action */
  164.             int done;            /* don't dump if action dumped (used for predicates) */
  165.             int init_action;    /* is this the 1st action of 1st prod of block? */
  166.             char *pred_fail;    /* what to do/print when predicate fails */
  167. #ifdef __cplusplus
  168.         };
  169. #else
  170.         } ActionNode;
  171. #endif
  172.  
  173. #ifdef __cplusplus
  174. class TokNode : public Node {
  175. public:
  176. #else
  177. typedef struct _toknode {
  178.             NodeType ntype;
  179. #endif
  180.             Node *next;
  181.             char *rname;        /* name of rule it's in */
  182.             int file;            /* index in FileStr (name of file with rule) */
  183.             int line;            /* line number that token occurs on */
  184.             int token;
  185.             int astnode;        /* leaf/root/excluded (used to build AST's) */
  186.             unsigned char label;/* token label or expression ? */
  187.             unsigned char remapped;
  188.                                 /* used if token id's are forced to certain positions;
  189.                                  * a function walks the tree reassigning token numbers */
  190.             unsigned char upper_range;
  191.                                 /* used only if Token is of type T1..T2; in this case,
  192.                                  * use token..upper_range as the range; else
  193.                                  * upper_range must be 0 */
  194.             unsigned char wild_card;
  195.                                 /* indicates that the token is the "." wild-card;
  196.                                  * field token is ignored if wild_card is set
  197.                                  */
  198.             unsigned int elnum; /* element number within the alternative */
  199.             struct _junct *altstart;    /* pointer to node that starts alt */
  200.             struct _TCnode *tclass;        /* token class if tokclass ref */
  201.             set tset;            /* set of tokens represented by meta token */
  202.             char *el_label;        /* el_label:toknode */
  203.             unsigned char complement;    /* complement the set? */
  204.             ExceptionGroup *ex_group;    /* any exception[el_label] attached? */
  205.             unsigned char use_def_MT_handler;
  206. #ifdef __cplusplus
  207.         };
  208. #else
  209.         } TokNode;
  210. #endif
  211.  
  212. #ifdef __cplusplus
  213. class RuleRefNode : public Node {
  214. public:
  215. #else
  216. typedef struct _rrnode {
  217.             NodeType ntype;
  218. #endif
  219.             Node *next;
  220.             char *rname;        /* name of rule it's in */
  221.             int file;            /* index in FileStr (name of file with rule)
  222.                                    it's in */
  223.             int line;            /* line number that rule ref occurs on */
  224.             char *text;            /* reference to which rule */
  225.             char *parms;        /* point to parameters of rule invocation
  226.                                    (if present) */
  227.             char *assign;        /* point to left-hand-side of assignment
  228.                                    (if any) */
  229.             int linked;            /* Has a FoLink already been established? */
  230.             int astnode;        /* excluded? (used to build AST's) */
  231.             unsigned int elnum; /* element number within the alternative */
  232.             struct _junct *altstart;
  233.             char *el_label;        /* el_label:rrnode */
  234.             ExceptionGroup *ex_group;    /* any exception[el_label] attached? */
  235. #ifdef __cplusplus
  236.         };
  237. #else
  238.         } RuleRefNode;
  239. #endif
  240.  
  241. #ifdef __cplusplus
  242. class Junction : public Node {
  243. public:
  244. #else
  245. typedef struct _junct {
  246.             NodeType ntype;
  247. #endif
  248.             char ignore;        /* used by FIRST computation to ignore
  249.                                    empty alt added for the (...)+ blks */
  250.             char visited;        /* used by recursive routines to avoid
  251.                                    infinite recursion */
  252.             char pvisited;        /* used by print routines to avoid
  253.                                    infinite recursion */
  254.             char fvisited;        /* used by FoLink() to avoid
  255.                                    infinite recursion */
  256.             char *lock;            /* used by REACH to track infinite recursion */
  257.             char *pred_lock;    /* used by find_predicates to track infinite recursion */
  258.             int altnum;            /* used in subblocks. altnum==0 means not an
  259.                                    alt of subrule */
  260.             int jtype;            /* annotation for code-gen/FIRST/FOLLOW.
  261.                                    Junction type */
  262. #ifdef __cplusplus
  263.             Junction *end;        /* pointer to node with EndBlk in it
  264.                                    if blk == a block type */
  265. #else
  266.             struct _junct *end;    /* pointer to node with EndBlk in it
  267.                                    if blk == a block type */
  268. #endif
  269.             Node *p1, *p2;
  270.             char *rname;        /* name of rule junction is in */
  271.             int file;            /* index in FileStr (name of file with rule)
  272.                                    if blk == RuleBlk */
  273.             int line;            /* line number that rule occurs on */
  274.             int halt;            /* never move past a junction with halt==TRUE */
  275.             char *pdecl;        /* point to declaration of parameters on rule
  276.                                    (if present) */
  277.             char *parm;            /* point to parameter of block invocation
  278.                                    (if present) */
  279.             int predparm;        /* indicates that the 'parm' is a predicate
  280.                                  * to be used in the while loop generated
  281.                                  * for blocks */
  282.             char *ret;            /* point to return type of rule (if present) */
  283.             char *erraction;    /* point to error action (if present) */
  284.             int blockid;        /* this is a unique ID */
  285.             char *exception_label;    /* goto label for this alt */
  286.             set *fset;            /* used for code generation */
  287.             Tree *ftree;        /* used for code generation */
  288.             Predicate *predicate;/* predicate that can be used to disambiguate */
  289.             char guess;            /* true if (...)? block */
  290.             char approx;        /* limit block to use linear approx lookahead? */
  291.             set tokrefs;        /* if ith element of alt is tokref then i is member */
  292.             set rulerefs;        /* if ith element of alt is rule ref then i is member */
  293.             struct _ListNode *exceptions; /* list of exceptions groups for rule */
  294.             struct _ListNode *el_labels;  /* list of element labels for rule */
  295. #ifdef __cplusplus
  296.         };
  297. #else
  298.         } Junction;
  299. #endif
  300.  
  301. typedef struct { Node *left, *right; } Graph;
  302.  
  303.